package com.neusoft.yuejian_6.activity;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.adapter.TrainAdapter;
import com.neusoft.yuejian_6.javabean.Train;
import com.neusoft.yuejian_6.model.TrainModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class TrainRumenActivity extends Activity {

    private RecyclerView recyclerView;
    private View view = null;
    private ImageView back;
    private ImageView train_pic;
    private TextView train_name;
    private TextView train_type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_train_rumen);
        initViews();//初始化
        getData();//点击事件处理
        initEvent();
    }

    private void initViews() {
        recyclerView = (RecyclerView) findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局

        back=(ImageView) findViewById(R.id.back);
    }

    public void initEvent() {
        back.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                finish();
            }
        });}

    //获取列表数据
    private void getData() {
        TrainModel trainModel=new TrainModel();
        Call<List<Train>> call=trainModel.getRumenTrainlist();
        // System.out.print("t_name");
        call.enqueue(new Callback<List<Train>>() {
            @Override
            public void onResponse(Call<List<Train>> call, Response<List<Train>> response) {
                List<Train> data = response.body();  //获取数据
                System.out.printf("data");
                recyclerView.setAdapter(new TrainAdapter(TrainRumenActivity.this, data));
            }
            @Override
            public void onFailure(Call<List<Train>> call, Throwable t) {

            }
        });



    }


}

